package com.wenbai.servicelightluxurystickers.controller;

import com.wenbai.servicelightluxurystickers.entity.StickForum;
import com.wenbai.servicelightluxurystickers.service.StickForumService;
import com.wenbai.servicelightluxurystickers.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stick/forum")
public class StickForumController {
    @Autowired
    private StickForumService stickFourmService;

    @GetMapping("/selectForum")
    public Response<List<StickForum>> selectForumJoinUser(){
        List<StickForum> stickForums = stickFourmService.selectJoinUser();
        return Response.success(stickForums,"查询成功");
    }

    @GetMapping("/selectForumPage")
    public Response<List<StickForum>> selectForumPage(int startPage,int endPage){
        List<StickForum> stickForums = stickFourmService.selectByPage(startPage,endPage);
        return Response.success(stickForums,"查询成功");
    }

    @PostMapping("/insertForum")
    public Response<StickForum> insertForum(@RequestBody StickForum stickForum){
        StickForum  stickForums =  stickFourmService.insert(stickForum);
        return Response.success(stickForums,"插入成功");
    }

    @PostMapping("/updateForum")
    public Response<String> updateForum(@RequestBody StickForum stickForum){
        if (stickForum.getForumId() == null){
            return Response.error("更新失败，forumId不能为空");
        }
        stickFourmService.update(stickForum);
        return Response.success("更新成功");
    }

    @GetMapping("/deleteForum")
    public Response<String> deleteForum(int forumId){
        if (forumId == 0){
            return Response.error("删除失败，forumId不能为空");
        }
        stickFourmService.delete(forumId);
        return Response.success("删除成功");
    }

    /**
     * 根据userId修改热度
     * @param stickForum
     * @param userId
     * @return
     */
    @PostMapping("/setHot")
    public Response<String> setHot(@RequestBody StickForum stickForum , Long userId){
        stickFourmService.setHot(stickForum,userId);
        return Response.success("热度修改成功");
    }

    /**
     * 根据热度降序查询Forum
     * @return
     */
    @GetMapping("/hotSort")
    public Response<List<StickForum>> hotSort(){
        List<StickForum> stickForums  = stickFourmService.hotSort();
        return Response.success(stickForums,"查询成功");
    }
}
